package org.middlewaregr.services;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;

public class DbConnection {
	private static Connection connection;

	public static Connection getDbConnection() throws SQLException {
		if (connection == null || !connection.isClosed()) {
			String userName = "root";
			String password = "root";
			String url = "jdbc:mysql://localhost/middlewaregr";
			try {
				Class.forName("com.mysql.jdbc.Driver").newInstance();
			} catch (InstantiationException e) {
				throw new SQLException(e);
			} catch (IllegalAccessException e) {
				throw new SQLException(e);
			} catch (ClassNotFoundException e) {
				throw new SQLException(e);
			}

			connection = DriverManager.getConnection(url, userName, password);
		}
		return connection;
	}
}
